<template>
  <div id="Pick"
       v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="tableSelectData"
                  :title="$t('out.pickDetail1')"
                  @del="del"
                  @newCreate="newCreate"></v-tableTitle>
    <v-table :pageSize="pageSize"
             :page="page"
             :tableConfig="tableConfig"
             :tableData="tableData"
             :total="total"
             @findData="getTableData"
             @getTableData="getTableData"
             @searhData="searhData"
             @selectData="selectData"
             @setdialog="setdialog"
             @upData="getTableData"
             ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
  name: "pick",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('out.pickdetailkey'),
          prop: "pickdetailkey",
          input: "input",
        },
        {
          label: this.$t('out.orderkey'),
          prop: "orderkey",
          input: "input",
        },
        {
          label: this.$t('outbound.userlinenumber'),
          prop: "orderlinenumber",
          input: "input",
        },
        {
          label: this.$t('in.caseid'),
          prop: "caseid",
          input: "input",
        },
        {
          label: this.$t('in.lot'),
          prop: "lot",
          input: "input",
        },
        {
          label: this.$t('config.loc'),
          prop: "loc",
          input: "input",
        },
        {
          label: this.$t('in.lpn'),
          prop: "id",
          input: "input",
        },
        {
          label: this.$t('config.shipper'),
          prop: "storerkey",
          input: "input",
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input",
        },
        {
          label: this.$t('config.num'),
          prop: "qty",
          input: "input",
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("querycodeLkup/ORDRSTATUS")
        },
        {
          label: this.$t('out.dropid1'),
          prop: "dropid",
          input: "input",
        },
        {
          label: this.$t('out.wavekey'),
          prop: "wavekey",
          input: "input",
        },
        {
          label: this.$t('out.taskgroup'),
          prop: "rtxtaskgrp",
          input: "input",
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        // {label: this.$t('common.create'), certigier: this.newStatus, invalid: "newCreate"},
        { label: this.$t('common.delete'), certigier: this.deleteStatus||!this.btnPermNameList.includes('WM020201'), disabled: true, invalid: "del" },
      ]
    }
  },
  created () {
  },
  methods: {

    //新建
    async newCreate () {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: 'pickDeawer' });
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    //删除
    async del (data) {
      try {
        let res = await this.$api.post(`/deletepickdetail`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/querypickdetail/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog (data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'pickDeawer' });
    },
  },
  mounted () {
    ;
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = false;
        } else {
          this.deleteStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#Pick {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
